package com.cqie.rbac.controller;

import com.cqie.rbac.bo.MenuBo;
import com.cqie.rbac.service.ISysMenuService;
import com.cqie.rbac.util.Result;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 菜单实体 前端控制器
 * </p>
 *
 * @author 夏兵
 * @since 2021-09-02
 */
@RestController
@RequestMapping("/menu")
public class SysMenuController {

    @Autowired
    private ISysMenuService iSysMenuService;

    @GetMapping("/menuTree")
    @RequiresPermissions(value = {"all_menu", "add_menu", "modify_menu", "del_menu"}, logical = Logical.OR)
    public Result menuTree() {
        return iSysMenuService.menuTree();
    }

    @GetMapping("/getRoleMenu")
    @RequiresPermissions(value = {"all_role", "add_role", "modify_role"}, logical = Logical.OR)
    public Result getRoleMenu(Long id) {
        return iSysMenuService.getRoleMenu(id);
    }

    @GetMapping("/delMenu")
    @RequiresPermissions(value = {"all_role", "del_role"}, logical = Logical.OR)
    public Result delMenu(Long delId) {
        return iSysMenuService.delMenu(delId);
    }


    @GetMapping("/getMenuById")
    @RequiresPermissions(value = {"all_menu", "add_menu", "modify_menu"}, logical = Logical.OR)
    public Result getMenuById(Long id) {
        return iSysMenuService.getMenuById(id);
    }

    @PostMapping("/updateOrAddMenu")
    @RequiresPermissions(value = {"all_menu", "add_menu", "modify_menu"}, logical = Logical.OR)
    public Result updateOrAddMenu(@RequestBody MenuBo menuBo) {
        return iSysMenuService.updateOrAddMenu(menuBo);
    }

    @GetMapping("/getNavMenu")
    public Result getNavMenu() {
        return iSysMenuService.getNavMenu();
    }
}
